--[[/**
-- * 
 * 统计他的受伤次数
-- *
-- */]]

---@class BuffEffect92004101 : BaseBuffEffect
BuffEffect92004101 = ClientFight.CreateClass("BuffEffect92004101", ClientFight.BaseBuffEffect)
local t = BuffEffect92004101
t.BuffEffect92004101 = "BuffEffect92004101";
function t:add(fight, buff)
    local buffEffectValue = buff.buffBean.f_BuffEffectValue;
    local target = buff.target;
    local damageNum = target.parametersByObject[t.BuffEffect92004101] or 0;
    if (damageNum < buffEffectValue[1]) then
        --前3秒受到的伤害次数,未到达临界值
        SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff:" .. buff.modelId .. " 前N秒受到的伤害次数,未到达临界值:" .. buffEffectValue[1] .. " , 增加buff: " .. buffEffectValue[2]);
        local result = BuffManager.addBuff(fight, buff.skill, target, target, false, buffEffectValue[2], 1);
        local o = result[1];
        if (o == IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE) then
            local addBuff = result[2];
            buff.effectParams[t.BuffEffect92004101] = addBuff;
        end
    end
    target.parametersByObject[t.BuffEffect92004101] = 0;
 return ClientFight.BaseBuffEffect.add(self,fight, buff);
end

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local target = buff.target;
    local buffEffectValue = buff.buffBean.f_BuffEffectValue;
    local damageNum = target.parametersByObject[t.BuffEffect92004101] or 0;
    damageNum = damageNum + 1;
    if (damageNum < buffEffectValue[1]) then
        target.parametersByObject[t.BuffEffect92004101] = damageNum;
    end
    if (buffEffectValue[1] ~= damageNum) then
        return IBuffEffect.FAIL;
    end
    target.parametersByObject[t.BuffEffect92004101] = damageNum;
    local extBuffObj = buff.effectParams[t.BuffEffect92004101];
    if (extBuffObj ~= nil) then
        local extBuff = extBuffObj;
        BuffManager.removeFighterBuff(fight, target, extBuff, true);
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

function t:afterRemove(fight, buff)
    BuffManager.addBuff(fight, buff.skill, buff.target, buff.target, false, buff.modelId, 1);
end

t.New()